<template>
    <h1>登录页面</h1>

    <table>
        <tr>
            <td>用户名</td>
            <td><input type="text" v-model="Name" ></td>
        </tr>

        <tr>
            <td>密码</td>
            <td><input type="password" v-model="Pwd" ></td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="登录" @click="Login" >
            </td>
        </tr>

    </table>


</template>

<script setup lang="ts">

import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router = useRouter();

const Name = ref('');
const Pwd = ref('');

//登录功能
const Login =() =>{

    if(Name.value==''){
        alert('用户名不能为空');
        return;
    }


    axios({
        url:'http://localhost:62058/api/User/Login',
        method:'get',
        params:{
            Name:Name.value,
            Pwd:Pwd.value
        }
    })
    .then(function(res){

        console.log(res.data);

        if(res.data!=null){
            alert('登录成功');
            router.push('/Showlogin');
        }
        
        else{
            alert('登录失败');
        }
    })
    .catch(function(err){
        console.log(err)
    })
}

</script>